/*
 * PopupUserProfileFrame.hpp
 *
 *  Created on: Jul 25, 2012
 *      Author: guillou
 */

#ifndef POPUPUSERPROFILEFRAME_HPP_
#define POPUPUSERPROFILEFRAME_HPP_

#include <ui_userprofileframe.h>
#include <PopupUsersManager.hpp>

class PopupUserProfileFrame : public QFrame, private Ui_UserProfileFrame
{
  Q_OBJECT

public:
  PopupUserProfileFrame(QFrame *parent = 0)
  : QFrame(parent) {
    setupUi(this);
    setWindowFlags(Qt::Popup);
#if QT_VERSION >= 0x040500
    setAttribute(Qt::WA_TranslucentBackground, true);
#endif
    connect(m_avatar, SIGNAL(clicked()), this, SLOT(hide()));
  }

  bool setup(Popup::UserID p_userID) {
    PopupUserExt _user;
    if (PopupUsersManager::instance()->getUserInfo(_user, p_userID,
        Popup::POPUP_USER_FIELD_NICKNAME|
        Popup::POPUP_USER_FIELD_AVATAR))
    {
      if (_user.getAvatar().compare(BAD_AVATAR) != 0) {
        QIcon _icon;
        _icon.addFile(QString::fromUtf8(_user.getAvatar().c_str()));
        m_avatar->setIcon(_icon);
      }
      m_nickname->setText(_user.getNickname().c_str());
      return true;
    }
    return false;
  }

  void leaveEvent(QEvent*) {
    setVisible(false);
  }
};

#endif /* POPUPUSERPROFILEFRAME_HPP_ */
